Calculation Functions

Function Index

and bitand bitnot bitor bitxor false if ifError ifNA ifs not or switch true xor cell countBlank errorType isBlank isErr isError isEven isLogical isNA isNonText isNumber isOdd isRef isText n na type

Logical Functions


and(expression1, expression2, ...)

Returns 1/true if all the supplied expressions evaluate to non‑zero values and 0/false otherwise.

Text strings are converted to numbers. Text strings that can't be converted to numbers cause #NUM! errors. Empty cells are ignored. If there are no non‑empty cells, the function returns the #N/A! error value.

=and(1, 1, true, "1") returns 1
=and(a1 >= 0, a1 < 0)
=and({true, true, 1, 1}, {true, true, 1, 0}) returns 0
=and(345, 178) returns 1
=and(1, 2, 4, 8) returns 1


bitand(v1, v2, ...)

Performs a bitwise AND on two or more numeric values. If the specified parameters are expressions that evaluate to logical true (1) or false (0), the function returns 1 or 0 and is equivalent to plain logical AND.

All numbers are rounded to the nearest integers with up to 15 digits. Text strings are converted to numbers. Text strings that can't be converted to numbers cause #NUM! errors. Empty cells are ignored. If there are no non‑empty cells, the function returns the #N/A! error value.

=bitand(1, 1, true, "1") returns 1
=bitand(a1 >= 0, a1 < 0) returns 0
=bitand({true, true, 1, 1}, {true, false}) returns 0
=bitand(345, 178) returns 16
=bitand(1, 2, 4, 8) returns 0


bitnot(v, bits)
bitnot(v)

Returns the bitwise negation of v using the specified number of bits. The bits parameter must be in the range <1, 49>. If it is omitted, the default value is 16.

The second variant uses only one bit as the default value of bits and returns simple logical negation (1 or 0) of a logical expression.

=bitnot(1, 8) returns 254
=bitnot(1, 16) returns 65534
=bitnot(34, 8) returns 221
=bitnot(true) returns 0


bitor(v1, v2, ...)

Performs a bitwise OR on two or more numeric values. If the specified parameters are expressions that evaluate to logical true (1) or false (0), the function returns 1 or 0 and is equivalent to plain logical OR.

All numbers are rounded to the nearest integers with up to 15 digits. Text strings are converted to numbers. Text strings that can't be converted to numbers cause #NUM! errors. Empty cells are ignored. If there are no non‑empty cells, the function returns the #N/A! error value.

=bitor(1, 1, true, 1) returns 1
=bitor(a1 >= 0, a1 < 0) returns 1
=bitor(345, 178) returns 507
=bitor(1, 2, 4, 8) returns 15


bitxor(v1, v2, ...)

Performs a bitwise exclusive OR on two or more numeric values. If the specified parameters are expressions that evaluate to logical true (1) or false (0), the function returns 1 or 0.

All numbers are rounded to the nearest integers with up to 15 digits. Text strings are converted to numbers. Text strings that can't be converted to numbers cause #NUM! errors. Empty cells are ignored. If there are no non‑empty cells, the function returns the #N/A! error value.

=bitxor(1, 1) returns 0
=bitxor(a1 >= 0, a1 < 0) returns 1
=bitxor({true, true, 1, 1}, {true, false}) returns 1
=bitxor(345, 178) returns 491
=bitxor(1, 2, 4, 8) returns 15


false()

Returns 0.


if(v, if-true-expression, if-false-expression)

If v is true or simply evaluates to a positive integer number, the function returns the if-true-expression. Otherwise if-false-expression is returned. The returned expressions can be of any type: numbers, text, arrays, references or error codes.

If v is a text string or a floating point number, the corresponding conversion to an integer number is performed. Floating point v values are rounded to the nearest integer.

If v is an array or a range, the if() function becomes an array formula returning an array of the v size. As specified in the “Using Array Formulas” help topic the rules of using array arguments require that if-true-expression and if-false-expression must be either a single (scalar) value or an array/range of the same size.

=if((1 > 0)*(2 > 0), {1, 2}, {4, 5}) returns {1, 2}
=if("ab" > "a", 1, #N/A!) returns 1
=if(b1="abc", c1:c5, d1:d10) returns one of the two references c1:c5 or d1:d10 depending on the value of b1.
=if(b1:c5 > 100, "ok", b1:c5) returns an array of b1:c5 values with the “ok” text replacing values > 100.
=if(isError(b1:c5), errorType(b1:c5)=0, b1:c5) returns an array of b1:c5 values with errors converted to 0.
=if(isError(b1:c5), if(errorType(b1:c5)=0, "", ""), b1:c5) the same as above except that empty "" strings are displayed instead of zeroes.


ifError(data [, replacement])

If the data parameter evaluates to any error value, the replacement is returned (or an empty cell if replacement is omitted).

Data can be any expression: a value, reference, or array.


ifNA(data [, replacement])

If the data parameter is the #N/A! error value, the replacement is returned (or an empty cell if replacement is omitted).

Data can be any expression: a value, reference, or array.


ifs(condition1, value1, [condition2, value2, ...])

Evaluates multiple conditions condition1, condition2, ... and returns a value that corresponds to the first true condition. The evaluation is performed from left to right. If conditions are arrays/ranges, all must have the same size.

=ifs(A1 > 0.75, "above 75 %", A1 > 0.5, "above 50%", A1 > 0.25, "above 25%")
=ifs({1, 2, 3, 4, 5} > 2, ">2", {1, 2, 3, 4, 5}=1, "equal 1") returns {"equal 1", #N/A!, ">2", ">2", ">2"}


not(v)

Returns the negation of a logical expression (as 1 or 0).

=not(1) returns 0
=not(1.1) returns 0
=not(0) returns 1
=not(true) returns 0


or(v1, v2, ...)

Returns 1/true if at least one of the specified expressions evaluates to a non‑zero value and 0/false otherwise.

Text strings are converted to numbers. Text strings that can't be converted to numbers cause #NUM! errors. Empty cells are ignored. If there are no non‑empty cells, the function returns the #N/A! error value.

=or(1, 1, true, 1) returns 1
=or(a1 >= 0, a1 < 0)
=or(345, 178) returns 1
=or(1, 2, 4, 8) returns 1


switch(expression, case1, value1, [case2, value2, ...], [default])

Tests the value of the expression against the case1, case2, ... values and, if a matching case value is found, returns the corresponding value. If no matching case value is found, the #N/A! error value is returned (or the optional default value if specified).

=SWITCH(A5, "dog", "mammal", "falcon", "bird")
=SWITCH(A1:A10, 1, "one", 2, "two", 3, "three", "etc.")


true()

Returns 1.


xor(expression1, expression2, ...)

Returns 1/true if there is an odd number of logical expressions that evaluate to 1/true and 0/false otherwise.

Text strings are converted to numbers. Text strings that can't be converted to numbers cause #NUM! errors. Empty cells are ignored. If there are no non‑empty cells, the function returns the #N/A! error value.

=xor(1, 1, true) returns 1
=xor(a1 >= 0, a1 < 0)
=xor({true, true, 1, 1}, {true, 1}) returns 0
=xor(345, 178) returns 0
=xor(1, 2, 3) returns 1

Informational Functions


cell(type, [reference])

Depending on the type value the function returns:

"address": the specified reference as text
"col": column number of the specified cell
"row": row number of the specified cell
"color": 1 if the current cell format is set to display negative numbers in red; 0 otherwise
"contents": value of the specified cell
"filepath": filename and full path of current document
"format": symbol of the format code of the specified cell, as listed below
"parentheses": 1 if the current cell format is set to display negative numbers in parentheses; 0 otherwise
"prefix": single quotation mark (') if the cell contents is left‑aligned, double quotation mark (") if the cell contents is right‑aligned, caret (^) if the cell contents is centered, empty text in all other cases
"protect": 1 if the specified cell is protected
"type": "b" if the cell is empty, "l" if the cell contains text, "v" in all other cases
"width": number of characters in the default font size fitting in the specified column

General "G"
0 "F0"
#,##0 ",0"
0.00 "F2"
#,##0.00 ",2"
$#,##0_);($#,##0) "C0"
$#,##0_);[Red]($#,##0) "C0-"
$#,##0.00_);($#,##0.00) "C2"
$#,##0.00_);[Red]($#,##0.00) "C2-"
0% "P0"
0.00% "P2"
0.00E+00 "S2"
# ?/? or # ??/?? "G"
m/d/yy or m/d/yy h:mm or mm/dd/yy "D4"
d-mmm-yy or dd-mmm-yy "D1"
d-mmm or dd-mmm "D2"
mmm-yy "D3"
mm/dd "D5"
h:mm AM/PM "D7"
h:mm:ss AM/PM "D6"
h:mm "D9"
h:mm:ss "D8"

=cell("address", sheet1!$a$2) returns "sheet1!$A$2"
=cell("address", sheet1!a2) returns "sheet1!A2"
=cell("width", b10) returns 9


countBlank(v1, v2, ...)

Counts empty cells and cells containing empty strings for the specified list of arguments.

=countBlank({1, 2, 3,,}, {""},,) returns 5


errorType(error)

Returns an integer representing a given error value.

For the complete list of error codes, please see the “Data types” help topic.


isBlank(x)

Returns 1 if x refers to an empty cell or an empty string, 0 otherwise.

=isBlank("") returns 1


isErr(x)

Returns 1 if x is an error value except #N/A!, 0 otherwise.

=isErr(1/0) returns 1
=isErr(#SYNTAX!) returns 1


isError(x)

Returns 1 if x is an error value, 0 otherwise.

=isError(#N/A!) returns 1


isEven(n)

Returns 1 if n is even, 0 otherwise. All numbers are rounded to the nearest integers.

=isEven(12) returns 1
=isEven(12.6) returns 0


isLogical(n)

Returns 1 if n is 1 or 0, 0 otherwise.

=isLogical(1) returns 1


isNA(error)

Returns 1 if error refers to the #N/A! value, 0 otherwise.

=isNA(#N/A!) returns 1


isNonText(x)

Returns 1 if x refers to any value that is not a text string, 0 otherwise.

=isNonText("") returns 0
=isNonText(1) returns 1


isNumber(x)

Returns 1 if x represents a number (which also includes a string that can be converted to a number), 0 otherwise.

=isNumber(9) returns 1
=isNumber("9") returns 1


isOdd(n)

Returns 1 if n is odd, 0 otherwise. All numbers are rounded to the nearest integers.

=isOdd(12) returns 0
=isOdd(12.6) returns 1


isRef(x)

Returns 1 if x is a reference, 0 otherwise.

=isRef(a1) returns 1
=isRef({1,2,3}) returns 0


isText(x)

Returns 1 if x represents a text string, 0 otherwise.

=isText("a") returns 1


n(x)

Converts x to a number.

=n("2005") returns 2005


na()

Returns the #N/A! error value.

=na() returns #N/A!


type(x)

Returns the type of x:

1 – Number
2 – Text
16 – Error value
64 – Array

=type(1) returns 1
=type({1, 2, 3}) returns 64